namespace :activetest do
  desc "A full corpus of test methods. Loads given files or all test libraries by default."
  task :agiledox do
    # get our command-line arguments
    args = ARGV.dup; args.shift
    # put ourselves in the load path
    $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
    require 'active_test'
    require 'action_controller/integration'
    # catalogue standard libraries
    standard_lib = []; ObjectSpace.each_object(Class) { |k| standard_lib << k }

    # require the test files
    tests = !args.empty? ? args : FileList['test/**/*_test.rb']
    tests.each { |file| require file }

    # determine everything loaded which needs testing
    added = []; ObjectSpace.each_object(Class) do |k|
      added << k if Test::Unit::TestCase > k && !k.name[/^ActiveTest/] && !standard_lib.include?(k)
    end

    # do our little bit of magic
    added.each do |lib|
      puts "#{lib.name.sub(/Test$/, '')} should:\n"
      lib.instance_methods.each do |method|
        next unless method =~ /test_(should_)?(.*)/
        puts " - #{$2.gsub('_', ' ')}"
      end
      puts "\n"
    end

    # wonderfully unintuitive CLI
    Test::Unit.run = true
  end
end